document.addEventListener('DOMContentLoaded', function () {
    tops();
    animation();
});

function animation() {
    // 客服位置居中
    var cs = document.querySelector('.customer-service');
    if (cs) {
        cs.style.marginTop = -(cs.offsetHeight / 2) + "px";

        const toggle = cs.querySelector('.customer-service-toggle');
        toggle.addEventListener('click', function () {
            if (toggle.classList.contains('on')) {
                cs.style.right = "-129px";
                toggle.classList.remove("on");
                toggle.querySelector('font').textContent = "<<";
            } else {
                cs.style.right = "0px";
                toggle.classList.add("on");
                toggle.querySelector('font').textContent = ">>";
            }
        });
    }
}

function tops() {
    const topBtn = document.createElement('a');
    topBtn.className = 'top';
    topBtn.innerHTML = "<i class='i-ico'></i>";
    document.body.appendChild(topBtn);

    window.addEventListener('scroll', function () {
        if (document.documentElement.scrollTop > 1000 || document.body.scrollTop > 1000) {
            topBtn.style.display = 'block';
        } else {
            topBtn.style.display = 'none';
        }
    });

    topBtn.addEventListener('click', function () {
        window.scrollTo({ top: 0, behavior: 'smooth' });
    });
}


loadCustom({ selector: '[data-service]', defaultPath: 'service.html'});

